package com.zhipu.resetbalance.ui.home.system.inspector;

import android.app.Activity;

import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.SPUtils;
import com.blankj.utilcode.util.TimeUtils;
import com.lxj.xpopup.XPopup;
import com.lxj.xpopup.enums.PopupAnimation;
import com.zhipu.resetbalance.listener.ChooseClickCallback1;
import com.zhipu.resetbalance.mobile.event.InspectorEntity;
import com.zhipu.resetbalance.pop.inspector.AddInspectorPopup;

public class InspectorViewModel extends ViewModel {


    /**
     * 自动打印
     */
    public MutableLiveData<Boolean> inspector = new MutableLiveData<>(false);







    public void AddPersonnel(){
        Activity mActivity = ActivityUtils.getTopActivity();
        AddInspectorPopup mAddInspectorPopup = new AddInspectorPopup(mActivity);
        mAddInspectorPopup.setChooseClickCallback1(new ChooseClickCallback1() {
            @Override
            public void onChooseClickCallback(String mData) {
                InspectorEntity mInspectorEntity = new InspectorEntity();
                mInspectorEntity.InspectorName = mData;
                mInspectorEntity.creationTime = TimeUtils.getNowMills();
                if(mInspectorEntity.save()){
                    inspector.setValue(true);
                }
            }
        });
        new XPopup
                .Builder(mActivity)
                .popupAnimation(PopupAnimation.ScaleAlphaFromCenter)
                .asCustom(mAddInspectorPopup)
                .show();
    }




    public void AddPersonnel(InspectorEntity mInspectorEntity){
        Activity mActivity = ActivityUtils.getTopActivity();
        AddInspectorPopup mAddInspectorPopup = new AddInspectorPopup(mActivity,mInspectorEntity);
        mAddInspectorPopup.setChooseClickCallback1(new ChooseClickCallback1() {
            @Override
            public void onChooseClickCallback(String mData) {
                mInspectorEntity.InspectorName = mData;
                mInspectorEntity.creationTime = TimeUtils.getNowMills();
                mInspectorEntity.update();
            }
        });
        new XPopup
                .Builder(mActivity)
                .popupAnimation(PopupAnimation.ScaleAlphaFromCenter)
                .asCustom(mAddInspectorPopup)
                .show();
    }



    public void shutDown(){
        //
        ActivityUtils.finishActivity(InspectorActivity.class);
    }

}
